@page "/Gateway/ReferenceGrant"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using Entity.Crd.Gateway
@using k8s.Models
@inherits BlazorApp.Pages.Common.TableBase<Entity.Crd.Gateway.V1Alpha2ReferenceGrant>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd>
                <SearchToolBar Title=@L["ReferenceGrant"] Count="@TableData.Total"
                               OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection" TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1Alpha2ReferenceGrant"
                               OnNsSelected="OnNsSelectedHandler"
                               HideNsSelector="true">
                </SearchToolBar>
            </HTd>
        </HTr>
        <HTr>
            <HTd>
                <Table TItem="V1Alpha2ReferenceGrant"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title="@L["Name"]">
                        <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Field="@context.Namespace()" Title="@L["Namespace"]" Width="110px"/>
                    <AntDesign.Column Title="@L["From"]" TData="string" Width="450px">
                        @if (context.Spec.ReferenceGrantFrom is { Count: > 0 })
                        {
                            <GridRow Class="grid-table">
                                <GridCol Span="12">Group</GridCol>
                                <GridCol Span="6">Kind</GridCol>
                                <GridCol Span="6">Namespace</GridCol>
                            </GridRow>
                            @foreach (var item in context.Spec.ReferenceGrantFrom)
                            {
                                <GridRow Class="grid-table">
                                    <GridCol Span="12">@item.Group</GridCol>
                                    <GridCol Span="6">@item.Kind</GridCol>
                                    <GridCol Span="6">@item.Namespace</GridCol>
                                </GridRow>
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title="@L["To"]" TData="string" Width="450px">
                        @if (context.Spec.ReferenceGrantTo is { Count: > 0 })
                        {
                            <GridRow Class="grid-table">
                                <GridCol Span="12">Group</GridCol>
                                <GridCol Span="6">Kind</GridCol>
                                <GridCol Span="6">Name</GridCol>
                            </GridRow>
                            @foreach (var item in context.Spec.ReferenceGrantTo)
                            {
                                <GridRow Class="grid-table">
                                    <GridCol Span="12">@item.Group</GridCol>
                                    <GridCol Span="6">@item.Kind</GridCol>
                                    <GridCol Span="6">@item.Name</GridCol>
                                </GridRow>
                            }
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title="@L["Age"]" TData="string" Width="100px">
                        <AgeView Age="@context.CreationTimestamp()"></AgeView>
                    </AntDesign.Column>
                    <ActionColumn Title="@L["Action"]" Width="100px">
                        <ReferenceGrantAction Item="@context"></ReferenceGrantAction>
                    </ActionColumn>
                </Table>
            </HTd>
        </HTr>
    </HTable>
    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1Alpha2ReferenceGrant"></ResourceWatcher>
}
